<template>
    <el-dialog :title="title" :visible.sync="dialogVisible" width="1100px" append-to-body>
        <el-form ref="form" :model="model" :rules="rules" inline label-width="170px" label-suffix=":" class="prod-form-class" v-loading="loading">
            <el-form-item label="ID" prop="id">
                <el-input v-model.trim="model.id" placeholder="" clearable disabled></el-input>
            </el-form-item>
            <el-form-item v-if="model.id === undefined " label="日期" prop="create_time">
                <el-date-picker v-model="model.create_time" type="datetime" placeholder="请选择日期" clearable></el-date-picker>
            </el-form-item>
            <el-form-item label="最长缺货未发订单日期" prop="long_not_send_date">
                <el-date-picker v-model="model.long_not_send_date" type="datetime" placeholder="请选择时间" clearable></el-date-picker>
            </el-form-item>
            <el-form-item label="最长有货未发订单日期" prop="long_have_send_date">
                <el-date-picker v-model="model.long_have_send_date" type="datetime" placeholder="请选择时间" clearable></el-date-picker>
            </el-form-item>
            <el-form-item label="出库订单数量" prop="out_order_quantity">
                <el-input v-model.trim="model.out_order_quantity" placeholder="请输入出库订单数量" clearable></el-input>
            </el-form-item>
            <el-form-item label="入库件数" prop="in_inventory_quantity">
                <el-input v-model.trim="model.in_inventory_quantity" placeholder="请输入入库件数" clearable></el-input>
            </el-form-item>
            <el-form-item label="出库件数" prop="out_inventory_quantity">
                <el-input v-model.trim="model.out_inventory_quantity" placeholder="请输入出库件数" clearable></el-input>
            </el-form-item>
            <el-form-item label="昨日采购数" prop="last_buy_quantity">
                <el-input v-model.trim="model.last_buy_quantity" placeholder="请输入昨日采购数" clearable></el-input>
            </el-form-item>
            <el-form-item label="昨日到货数" prop="last_arrive_quantity">
                <el-input v-model.trim="model.last_arrive_quantity" placeholder="请输入昨日到货数" clearable></el-input>
            </el-form-item>
            <el-form-item label="未发订单数" prop="not_send_order">
                <el-input v-model.trim="model.not_send_order" placeholder="请输入未发订单数" clearable></el-input>
            </el-form-item>
            <el-form-item label="缺货未发" prop="out_send_stock">
                <el-input v-model.trim="model.out_send_stock" placeholder="请输入缺货未发" clearable></el-input>
            </el-form-item>
            <el-form-item label="有货待发" prop="have_send_stock">
                <el-input v-model.trim="model.have_send_stock" placeholder="请输入有货待发" clearable></el-input>
            </el-form-item>
            <el-form-item v-if="model.id > 0 " label="更新时间" prop="update_time">
                <el-date-picker v-model="model.update_time" type="datetime" placeholder="请选择时间" clearable></el-date-picker>
            </el-form-item>
            
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" :loading="save" :disabled="save" @click="submit">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
import { editStatement, addStatement } from '@/api/product'
import { parseTime } from '@/utils/quickadmin'
export default {
    name: 'StatementDetailDialog',
    props: {
        value: {
            type: Boolean,
            default: false,
            required: true,
        },
        params: {
            type: Object,
            default: () => {},
        },
        type: {
            type: String,
            default: '',
        },
    },
    data() {
        return {
            loading: false,
            save: false,
            model: {
                id: undefined,
                out_order_quantity: undefined,
                in_inventory_quantity: undefined,
                out_inventory_quantity: undefined,
                last_buy_quantity: undefined,
                last_arrive_quantity: undefined,
                not_send_order: undefined,
                out_send_stock: undefined,
                have_send_stock: undefined,
                long_not_send_date: undefined,
                long_have_send_date: undefined,
                create_time: undefined,
                update_time: undefined,
            },
            rules: {},
        }
    },
    computed: {
        title() {
            return `${this.params.id ? '编辑' : '新增'}产品库存`
        },
        dialogVisible: {
            get() {
                return this.value
            },
            set(val) {
                this.$emit('input', val)
            },
        },
    },
    mounted() {
        this.model = Object.assign({}, this.model, this.params)
    },
    methods: {
        submit() {
            const params = {
                ...this.model,
                long_have_send_date: parseTime(this.model.long_have_send_date, 'y-m-d h:i:s'),
                create_time: parseTime(this.model.create_time, 'y-m-d h:i:s'),
                update_time: parseTime(this.model.update_time, 'y-m-d h:i:s'),
                long_not_send_date: parseTime(this.model.long_not_send_date, 'y-m-d h:i:s'),
            }
            if (this.save) {
                return
            }
            this.save = true
            const request = this.params.id ? editStatement : addStatement
            request(params)
                .then(res => {
                    this.$message.success(res.msg)
                    this.dialogVisible = false
                    this.$emit('success')
                })
                .finally(() => {
                    this.save = false
                })
        },
        cancel() {
            this.dialogVisible = false
        },
    },
}
</script>

<style>
.prod-form-class.el-form .el-form-item {
    width: 50%;
    margin-right: 0;
}
.prod-form-class.el-form .el-form-item .el-input {
    width: 250px;
}
.prod-form-class.el-form .el-form-item.w750 {
    width: 100%;
}
.prod-form-class.el-form .el-form-item.w750 .el-input {
    width: 770px;
}
.prod-form-class.el-form .el-form-item .el-textarea {
    width: 770px;
}
.prod-form-class.el-form .el-form-item.full {
    width: 100%;
}
.prod-form-class.el-form .el-form-item.full .el-input,
.prod-form-class.el-form .el-form-item.full .el-cascader {
    width: 770px;
}
.prod-form-class.el-form .el-form-item.w120 .el-input-number.w120 + .el-input-number {
    margin-left: 10px;
}
.prod-form-class.el-form .el-form-item .el-input-number,
.prod-form-class.el-form .el-form-item .el-input-number .el-input {
    width: 250px;
}
.prod-form-class.el-form .el-form-item.w120 .el-input-number.w120,
.prod-form-class.el-form .el-form-item.w120 .el-input-number.w120 .el-input {
    width: 120px;
}
.prod-form-class.el-form .el-input-number.is-without-controls .el-input__inner {
    text-align: left;
}
.custom-select .el-select-dropdown__item {
    max-width: 450px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
</style>
